home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / Reminder Manager / Main.c < prev    next >
C/C++ Source or Header  |  1995-06-24  |  6KB  |  203 lines

  1. #include "Lose.h"
  2. #include "Danger.h"
  3. #include "About.h"
  4. #include "Play.h"
  5. #include "MenuOn.h"
  6. #include "DoMenu.h"
  7. #include "Main.h"
  8. #include "Chimer.h"
  9. #include "DebugDisplay.h"
  10.  
  11. #define        NIL        0
  12.  
  13. char            ShowDebugFlag = TRUE;         // Show our debug window
  14. char            PlayingFlag = FALSE;        // Noise in progress flag
  15. char            inFrontFlag    = TRUE;            // Frontmost application flag
  16. short            MasterVolume = 100;            // How much overall volume
  17. short            BallFrequency = 255;        // How often new balls are dropped
  18. long            Resolution = 5;                // How many times to skip before going on
  19. long            ResolutionCounter = 0;        // Keep track of the times
  20. short            wherewasI = 0;                // Loop Counter for Play1
  21.  
  22. unsigned long    fudgefactor = 50;            // how unstarving before play?
  23. unsigned long    fudgefactor2 = 10;            // how high load before storm starts brewing?
  24.  
  25. long            starvation = 0;                // how often we get execution cycles
  26. unsigned long    starvTickCount = 0;            // the last time we got an execution chance
  27. long            starvIncrement = 1;            // the bonus multiplier fudge factor
  28. long            starvDecrement = 1;            // how many ticks to take off the stack per go-round
  29. long            deltastarv = 0;
  30.  
  31. long            nextShower = 1;                // the minutes of the next time (with bogus init value)
  32. long            showerInterval = 15;        // minutes between showers
  33. long            showerDuration = 10;        // seconds (roughly)
  34.  
  35. long            dissatisfaction = 0;        // pressure builds up.
  36. long            dissIncrement = 2;            // how fast.
  37. long            dissDecrement = 2;            // how many ticks to take off the stack per go-round
  38.  
  39. void main()
  40. {
  41.     char           doneFlag = FALSE;
  42.     char        Is_A_Dialog;
  43.     char        stillInGoAway;
  44.     char        ch;
  45.     short       code;
  46.     short       theMenu,theItem;
  47.     short       chCode;
  48.     long        mResult;
  49.     WindowPtr   whichWindow;
  50.     EventRecord myEvent;
  51.     TEHandle    theInput = NIL;
  52.     Rect        tempRect,OldRect;
  53.     Point       myPt;
  54.     GrafPtr     SavePort;
  55.  
  56.     /* Warm up the Mac */
  57.     InitGraf(&qd.thePort);
  58.     InitFonts();
  59.     FlushEvents(everyEvent,0);
  60.     InitWindows();
  61.     InitMenus();
  62.     TEInit();
  63.     InitDialogs(NIL);
  64.     InitCursor();
  65.  
  66.     InitMyMenus();
  67.     InitChimer();
  68.     Init_About();
  69.                     // shut up and play yer guitar
  70. //    Open_About();
  71.     Init_Play();
  72.  
  73.     do
  74.     {
  75.         if (PlayingFlag)    
  76.             Play1();
  77.         
  78.         if (theInput != NIL)
  79.             TEIdle(theInput);
  80.  
  81.         SystemTask();
  82.  
  83.  
  84.         if (WaitNextEvent(everyEvent, &myEvent, 5, nil))
  85.         {
  86.             code = FindWindow(myEvent.where, &whichWindow);
  87.  
  88.  
  89.             switch (myEvent.what)
  90.             {
  91.                 case mouseDown:
  92.                     if (code == inSysWindow) /* Is the event in a DA window? */
  93.                     {
  94.                         /* Send event to system to handle */
  95.                         SystemClick(&myEvent, whichWindow);
  96.                     }
  97.  
  98.                     if (code == inMenuBar) // Menu happening
  99.                     {
  100.                         AdjustMenus();
  101.                         mResult = MenuSelect(myEvent.where);
  102.                         theMenu = HiWord(mResult);
  103.                         theItem = LoWord(mResult);
  104.                         DoMenu(&doneFlag,theMenu,theItem,&theInput);
  105.                     }
  106.   
  107.                     if (code == inContent)
  108.                     {
  109.                         if (whichWindow != FrontWindow())
  110.                         {
  111.                             SelectWindow(whichWindow);// Select the window, bring to front */
  112.                         }
  113.                         else            // Window is already selected */
  114.                         {
  115.                             SetPort(whichWindow);
  116.                             switch (GetWRefCon(whichWindow)) // Which window? */
  117.                             {
  118.                                 case 2:
  119.                                     /* The About window closes when touched */
  120.                                     Close_About();
  121.                                     break;
  122.                             }
  123.                         }
  124.                     } /* inContent */
  125.  
  126.  
  127.                     break;              /* End of mouseDown */
  128.  
  129.                 case keyDown:
  130.                 case autoKey:
  131.                     ch = myEvent.message &  charCodeMask;
  132.                     if (myEvent.modifiers & cmdKey)/* Was CMD key down? */
  133.                     {
  134.                         AdjustMenus();
  135.                         mResult = MenuKey(ch);/* Is it a menu selection? */
  136.                         theMenu = HiWord(mResult);
  137.                         theItem = LoWord(mResult);
  138.                         if (theMenu != 0) /* If it is a menu selection... */
  139.                             DoMenu(&doneFlag, theMenu, theItem, &theInput);
  140.                         
  141.                         if (((ch == 'x') || (ch == 'X')) && (theInput != NIL))
  142.                             TECut(theInput);/* Handle a Cut in a TE area */
  143.                             
  144.                         if (((ch == 'c') || (ch == 'C')) && (theInput != NIL))
  145.                             TECopy(theInput);/* Handle a Copy in a TE area */
  146.                             
  147.                         if (((ch == 'v') || (ch == 'V')) && (theInput != NIL))
  148.                             TEPaste(theInput);/* Handle a Paste in a TE area */
  149.                     } /* End of Command key processing */
  150.                     
  151.                     else if (theInput != NIL) /* Is a TE Running?  */
  152.                         /* Get TextEdit to do it */
  153.                         TEKey(ch,theInput);
  154.                     break;
  155.  
  156.                 case updateEvt: /* Some window needs updating */
  157.                     whichWindow = (WindowPtr)myEvent.message;
  158.                     GetPort(&SavePort);
  159.                     BeginUpdate(whichWindow);
  160.                     SetPort(whichWindow);
  161.                     switch (GetWRefCon(whichWindow))
  162.                     {
  163.                         case 2:
  164.                             Update_About();
  165.                             break;
  166.                         case 3:
  167.                             UpdateDisplay();
  168.                             break;
  169.                     }
  170.                     EndUpdate(whichWindow);
  171.                     SetPort(SavePort);
  172.                     break;
  173.  
  174.                 case diskEvt:           /*  Disk inserted event */
  175.                     if (HiWord(myEvent.message) != 0) /* See if a disk mount error */
  176.                     {                                 /* due to unformatted disk inserted */
  177.                         myEvent.where.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) / 2) 
  178.                                             - (304 / 2);
  179.                         myEvent.where.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) / 3) 
  180.                                             - (104 / 2);
  181.                         InitCursor();/* Make sure it has an arrow cursor */
  182.                         theItem = DIBadMount(myEvent.where, myEvent.message);/* Let the OS handle the diskette */
  183.                     }
  184.                     break;
  185.  
  186.  
  187.                 case activateEvt:       /* Window activated event */
  188.                     /* Check if activation, not deactivation */
  189.                     if ((whichWindow != NIL) && (myEvent.modifiers & activeFlag))
  190.                         SelectWindow(whichWindow);
  191.                     break;
  192.                  
  193.                 default: 
  194.                     break;
  195.  
  196.             }                           /* End of Switch */
  197.  
  198.         }                               /* End of GetNextEvent */
  199.     }                                   /* End of do */
  200.     while (doneFlag ==  FALSE);
  201.  
  202. }                                       /* End of MAIN -- non-APPE */
  203.